package org.unei.multiprocessor.sharememory;

public class RegMRSWRegister implements Register<Byte>{

	private static int RANGE=Byte.MAX_VALUE-Byte.MIN_VALUE+1;
	boolean[] r_bit=new boolean[RANGE];
	
	public RegMRSWRegister(int capacity){
		for(int i=1;i<r_bit.length;i++){
			r_bit[i]=false;
			r_bit[0]=true;
		}
	}
	
	@Override
	public Byte read() {
		for(int i=0;i<RANGE;i++){
			if(r_bit[i])
				return (byte) i;
		}
		return -1;
	}

	@Override
	public void write(Byte v) {
		r_bit[v]=true;
		for(int i=v-1;i>=0;i--){
			r_bit[i]=false;
		}
	}

}
